package com.lk.dao;

import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.List;

import com.lk.util.DBHelp;
import com.lk.util.RowMapper;
import com.lk.entity.Folder;

public class FolderDao {
	
	DBHelp<Folder> db = new DBHelp<Folder>();
	
	public void save(Folder f){
		String sql = "insert into t_folder(id,f_name,f_size,t_createTime,t_project_id,t_employee_id,f_createMan) values(?,?,?,?,?,?,?)";
		db.executeSQL(sql,f.getFo_id(),f.getFo_name(),f.getFo_size(),f.getFo_createTime(),f.getT_project_id(),f.getT_employee_id(),f.getF_createMan());
	}
	
	public List<Folder> findAll(String t_project_id,String t_employee_id){
		String sql = "select id,f_name,f_size,t_createTime,t_project_id,t_employee_id,f_createMan from t_folder where t_project_id = ? and t_employee_id = ?";
		return db.executeSQLForList(sql, new FolderRowMapper(), t_project_id,t_employee_id);
	}
	
	public Folder findById(String id){
		String sql = "select id,f_name,f_size,t_createTime,t_project_id,t_employee_id,f_createMan from t_folder where id = ?";
		return db.executeSQLForObject(sql, new FolderRowMapper(), id);
	}
	
	public class FolderRowMapper implements RowMapper<Folder>{
		public Folder rowmapper(ResultSet rs) throws SQLException{
			Folder f = new Folder();
			f.setFo_id(rs.getString("id"));
			f.setFo_name(rs.getString("f_name"));
			f.setFo_size(rs.getString("f_size"));
			f.setFo_createTime(rs.getString("t_createTime"));
			f.setT_project_id(rs.getString("t_project_id"));
			f.setT_employee_id(rs.getString("t_employee_id"));
			f.setF_createMan(rs.getString("f_createMan"));
			return f;
		}
	}
}
